Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux'});
Ext.require([
             'Ext.grid.*',
             'Ext.data.*',
             'Ext.ux.grid.FiltersFeature',
             'Ext.toolbar.Paging',
             'Ext.ux.ajax.JsonSimlet',
             'Ext.ux.ajax.SimManager',
             'Ext.ux.grid.Printer'           
]);
Ext.define('TS.view.inv.ProductContactList' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.productcontactlist',
    title : '商品出入库流水',
    columnLines: true,
    bodyPadding:0,
    frame : true,
    closable: true,
    store:'inv.ProductContactStore',
    /* fields: ['id','invAddId','productId','batchNoId',
    'fyear', 'period','inQty','inAmt','outQty','outAmt','remQty',
    'remAmt','billId','billDetailId','billDate','customerId',
    'direct','summary','customerCode','customerName'
    ]*/
    columns:[
   		    {header: '单据日期', dataIndex: 'billDate',width:90},
            {header: '客户编号', dataIndex: 'customerCode',width:80},
            {header: '客户名称', dataIndex: 'customerName',width:160},
            {header: '批号',width:80,
            	renderer:function(value,metaData,record){
					if(Ext.isEmpty(record.raw.batchNo))
            			return '';
					return record.raw.batchNo.batchNo;
				}
			},
			{header:'存货地点',width:80,renderer:function(value,metaData,record){return record.raw.invAdd.inventoryAddName;}},
			{header: '方向 ', dataIndex: 'direct',width:60,renderer:function(value){if(value==1) return '收入'; else if(value==-1) return '发出'; else return '结转';}},
            {header: '本期入库', dataIndex: 'inQty',align:'right',width:80},
            {header: '入库金额', dataIndex: 'inAmt',width:80,align:'right'},
            {header: '本期出库', dataIndex: 'outQty',width:80,align:'right'},
            {header: '出库金额', dataIndex: 'outAmt',width:80,align:'right'},
            {header: '结存数量', dataIndex: 'remQty', width:80,align:'right'},
            {header: '结存金额', dataIndex: 'remAmt',width:80,align:'right'},
            {header: '摘要', dataIndex: 'summary',width:80},
            {header: '年份', dataIndex: 'fyear',width:50},
            {header: '期间', dataIndex: 'period',width:50}
            
    ],
	viewConfig:{
		getRowClass : function(record,rowIndex,rowParams,store){ 
			if(record.get('direct') == 0) {
				return 'grid-row-font-bold';
			} else {
				return '';
			}
		}
	},
	tbar:[
			{xtype:'button',text:'打印',action:'printBill',iconCls:'bill-printer-button',
				handler:function(button){
					var grid = button.up('gridpanel');
					Ext.ux.grid.Printer.print(grid);
				}
			},
			{xtype:'button',text:'导出',action:'exportBill',iconCls:'bill-export-button'}						      
	],
	initComponent:function(){
		var me = this;
		var store = me.getStore();
		this.dockedItems=[{
			xtype:'pagingtoolbar',
			store:store,
			dock:'bottom',
			displayInfo:true,
			items:[{
				xtype:'exporterbutton',
				component:me,
				text:'导出 Excel',
				iconCls:'bill-export-button'
			}]
		}];
		this.callParent(arguments);
	}
});
